package thread;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * date:2023-2-14
 * 阻塞队列的使用
 */
public class ThreadDemo21 {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue = new LinkedBlockingDeque<>();
        blockingQueue.put("hello");
        String res = blockingQueue.take();
        System.out.println(res);
        // 由于队列中只有一个 hello，所以下边再次取就会出现阻塞
        res = blockingQueue.take();
        System.out.println(res);
    }
}
